<?php


namespace App\Aspect;


use App\Annotation\Foo;
use App\Controller\Demo02Controller;
use App\Controller\IndexController;
use Hyperf\Di\Annotation\Aspect;
use Hyperf\Di\Aop\AbstractAspect;
use Hyperf\Di\Aop\ProceedingJoinPoint;

/**
 * @Aspect()
 * Class IndexAspect
 * @package App\Aspect
 */
class IndexAspect extends AbstractAspect
{
//    public $classes = [
//        Demo02Controller::class.'::index'
//    ];

    public $annotations = [
        Foo::class
    ];

    /**
     * @inheritDoc
     */
    public function process(ProceedingJoinPoint $proceedingJoinPoint)
    {
//        var_dump(__CLASS__);
//        var_dump('before');
//        $result = $proceedingJoinPoint->process();
//        var_dump('after');
//        return 'before '.$result.' after';

        $result = $proceedingJoinPoint->process();
        /** @var Foo $foo */
        $foo = $proceedingJoinPoint->getAnnotationMetadata()->class[Foo::class];
        $bar = $foo->bar;
        return $result + $bar;
    }
}